﻿using System;

namespace XamlFoundation.Foundation
{
    public static class Guard
    {
        /// <summary>
        /// Checks if the argument is not null and throws an <see cref="ArgumentNullException"/> if so.
        /// </summary>
        public static T ArgumentNotNull<T>(this T argument, string argumentName)
        {
            if (ReferenceEquals(argument, null))
            {
                throw  new ArgumentNullException(argumentName);
            }
            return argument;
        }

        /// <summary>
        /// Checks if the value is not null and throws an <see cref="NullReferenceException"/> if so.
        /// </summary>
        public static T NotNull<T>(this T value, string message)
        {
            if (ReferenceEquals(value, null))
            {
                throw new NullReferenceException(message);
            }
            return value;
        }
    }
}
